home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / toku3 / httrack-3.32-2.exe / {app} / src_win / WinHTTrack / InfoUrl.cpp < prev    next >
C/C++ Source or Header  |  2004-01-24  |  8KB  |  286 lines

  1. // InfoUrl.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. /* Externe C */
  7. extern "C" {
  8.   #include "HTTrackInterface.h"
  9.   #include "htscore.h"
  10. }
  11.  
  12. #include "Shell.h"
  13. #include "InfoUrl.h"
  14.  
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. extern HICON httrack_icon;
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CInfoUrl dialog
  25.  
  26.  
  27. CInfoUrl::CInfoUrl(CWnd* pParent /*=NULL*/)
  28.     : CDialog(CInfoUrl::IDD, pParent)
  29. {
  30.     //{{AFX_DATA_INIT(CInfoUrl)
  31.         // NOTE: the ClassWizard will add member initialization here
  32.     //}}AFX_DATA_INIT
  33. }
  34.  
  35.  
  36. void CInfoUrl::DoDataExchange(CDataExchange* pDX)
  37. {
  38.     CDialog::DoDataExchange(pDX);
  39.     //{{AFX_DATA_MAP(CInfoUrl)
  40.     DDX_Control(pDX, IDC_backlist, m_ctl_backlist);
  41.     DDX_Control(pDX, IDC_slider, m_slider);
  42.     //}}AFX_DATA_MAP
  43. }
  44.  
  45.  
  46. BEGIN_MESSAGE_MAP(CInfoUrl, CDialog)
  47.     //{{AFX_MSG_MAP(CInfoUrl)
  48.     ON_WM_TIMER()
  49.     ON_WM_CLOSE()
  50.     ON_BN_CLICKED(IDC_Freeze, OnFreeze)
  51.     ON_WM_CREATE()
  52.     ON_CBN_SELCHANGE(IDC_backlist, OnSelchangebacklist)
  53.     //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CInfoUrl message handlers
  58.  
  59. BOOL CInfoUrl::OnInitDialog() 
  60. {
  61.     CDialog::OnInitDialog();
  62.     
  63.   SetIcon(httrack_icon,false);
  64.   SetIcon(httrack_icon,true);  
  65.   SetForegroundWindow();   // yop en premier plan!
  66.  
  67.   // Patcher l'interface pour les Franτais ;-)
  68.   if (LANG_T(-1)) {    // Patcher en franτais
  69.     SetWindowTextCP(this, LANG_X1);
  70.     SetDlgItemTextCP(this, IDC_Freeze,LANG_X2);
  71.     SetDlgItemTextCP(this, IDC_STATIC_moreinfos,LANG_X3);
  72.     SetDlgItemTextCP(this, IDOK,LANG_CLOSE);
  73.   }
  74.  
  75.   StartTimer();
  76.     
  77.     return TRUE;  // return TRUE unless you set the focus to a control
  78.                   // EXCEPTION: OCX Property Pages should return FALSE
  79. }
  80.  
  81. void CInfoUrl::StartTimer() {
  82.   if (!timer) {
  83.     timer=SetTimer(WM_TIMER,100,NULL);
  84.   }
  85. }
  86. void CInfoUrl::StopTimer() {
  87.   if (timer) {
  88.     KillTimer(timer);
  89.     timer=0;
  90.     StatsBufferback=NULL;
  91.   }
  92. }
  93.  
  94. char* ToBool(int i) {
  95.   if (i)
  96.     return "yes";
  97.   else
  98.     return "no";
  99. }
  100.  
  101. char* ToStatuscode(int statuscode) {
  102.   if (statuscode<0) {
  103.     return "unknown status";
  104.   } else {
  105.     static char msg[1024];
  106.     msg[0]='\0';
  107.     infostatuscode(msg,statuscode);
  108.     return msg;
  109.   }
  110. }
  111.  
  112. char* ToStatus(int i) {
  113.   switch(i) {
  114.   case 0:
  115.     return "ready";
  116.     break;
  117.   case 1:
  118.     return "receiving";
  119.     break;
  120.   case 101:
  121.     return "searching dns";
  122.     break;
  123.   case 100:
  124.     return "waiting for connection";
  125.     break;
  126.   case 99:
  127.     return "receiving header";
  128.     break;
  129.   case 98:
  130.     return "receiving chunk header";
  131.     break;
  132.   case 1000:
  133.     return "ftp session";
  134.     break;
  135.   case -1:
  136.     return "empty";
  137.     break;
  138.   default:
  139.     return "unknown";
  140.     break;
  141.   }
  142. }
  143.  
  144. void CInfoUrl::OnTimer(UINT nIDEvent) 
  145. {
  146.   static char old_info[8192]="";
  147.   //
  148.   if (termine) {
  149.     EndDialog(IDOK);
  150.     return;
  151.   }
  152.   if (!StatsBufferback) return;
  153.   //
  154.   lien_back* back=(lien_back*) StatsBufferback;
  155.   //
  156.   if (m_ctl_backlist.GetDroppedState()==0) {
  157.     m_ctl_backlist.Clear();
  158.     m_ctl_backlist.ResetContent();
  159.     int i;
  160.     int back_max=StatsBufferback_max;
  161.     for(i=0;i<back_max;i++) {
  162.       if (termine) {
  163.         EndDialog(IDOK);
  164.         return;
  165.       }
  166.       if (back[i].status != -1) {
  167.         char st[HTS_URLMAXSIZE*4];
  168.         sprintf(st,"%02d: ",i);
  169.         strncatbuff(st,back[i].url_adr,256);
  170.         strncatbuff(st,back[i].url_fil,256);
  171.         m_ctl_backlist.AddString(st);
  172.       }
  173.     }
  174.   }
  175.   //
  176.   if (back) {
  177.     CInfoUrl box;
  178.     char info[8192]; info[0]='\0';
  179.     char total[256]; total[0]='\0';
  180.     char info100[256]; info100[0]='\0';
  181.     int offset=0;
  182.     if (back[id].status != -1) {        // utilisΘ
  183.       if (back[id].r.totalsize>0) {
  184.         sprintf(total,"%d",back[id].r.totalsize);
  185.         offset=(int) ((LONGLONG) ((LONGLONG) back[id].r.size*(LONGLONG) 100)/((LONGLONG) back[id].r.totalsize));
  186.         sprintf(info100,"(%d%%)",offset);
  187.       } else {
  188.         sprintf(total,"unknown");
  189.         sprintf(info100,"");
  190.       }
  191.       sprintf(info,"File: %s\r\nTotal length: %s\r\nBytes downloaded: %d %s\r\nCurrent state: %s",back[id].url_sav,total,back[id].r.size,info100,ToStatus(back[id].status));
  192.     }
  193.     //
  194.     if (strcmp(old_info,info)) {
  195.       char moreinfo[8192]; moreinfo[0]='\0';
  196.       lien_back* backitem=&back[id];
  197.       if (backitem) {
  198.         if (back[id].status != -1) {        // utilisΘ
  199.           sprintf(moreinfo+strlen(moreinfo),"Host: %s\r\n",backitem->url_adr);
  200.           sprintf(moreinfo+strlen(moreinfo),"File: %s\r\n",backitem->url_fil);
  201.           sprintf(moreinfo+strlen(moreinfo),"Name: %s\r\n",backitem->url_sav);
  202.           if (backitem->location_buffer)
  203.             if (backitem->location_buffer[0])
  204.               sprintf(moreinfo+strlen(moreinfo),"MoveToLocation: %s\r\n",backitem->location_buffer);
  205.             //
  206.             sprintf(moreinfo+strlen(moreinfo),"ContentType: %s\r\n",backitem->r.contenttype);
  207.             //
  208.             sprintf(moreinfo+strlen(moreinfo),"StatusCode: %d (%s)\r\n",backitem->r.statuscode,ToStatuscode(backitem->r.statuscode));
  209.             sprintf(moreinfo+strlen(moreinfo),"InternalStatus: %d (%s)\r\n",backitem->status,ToStatus(backitem->status));
  210.             if (backitem->r.msg[0])
  211.               sprintf(moreinfo+strlen(moreinfo),"StatusMessage: %s\r\n",backitem->r.msg);
  212.             //
  213.             sprintf(moreinfo+strlen(moreinfo),"HTTP/1.1: %s\r\n",ToBool(backitem->r.req.http11));
  214.             sprintf(moreinfo+strlen(moreinfo),"ChunkMode: %s\r\n",ToBool(backitem->r.is_chunk));
  215.             if (backitem->is_chunk)
  216.               sprintf(moreinfo+strlen(moreinfo),"CurrentChunkSize: %d\r\n",backitem->chunk_size);
  217.             //
  218.             sprintf(moreinfo+strlen(moreinfo),"TestMode: %s\r\n",ToBool(backitem->testmode));
  219.             sprintf(moreinfo+strlen(moreinfo),"HeadRequest: %s\r\n",ToBool(backitem->head_request));
  220.             sprintf(moreinfo+strlen(moreinfo),"NotModified: %s\r\n",ToBool(backitem->r.notmodified));
  221.             //
  222.             sprintf(moreinfo+strlen(moreinfo),"WriteToDisk: %s\r\n",ToBool(backitem->r.is_write));
  223.             sprintf(moreinfo+strlen(moreinfo),"LocalFile: %s\r\n",ToBool(backitem->r.is_file));
  224.             //
  225.             sprintf(moreinfo+strlen(moreinfo),"Size: %d\r\n",backitem->r.size);
  226.             sprintf(moreinfo+strlen(moreinfo),"TotalSize: %d\r\n",backitem->r.totalsize);
  227.         } else
  228.           strcpybuff(moreinfo,"Transfer complete in this buffer, waiting for next file");
  229.       }
  230.       //
  231.       SetDlgItemTextCP(this, IDC_InfoUrl,info);
  232.       SetDlgItemTextCP(this, IDC_Info100,info100);
  233.       SetDlgItemTextCP(this, IDC_MoreInfoUrl,moreinfo);
  234.       //
  235.       m_slider.SetRange(0,100);
  236.       m_slider.SetPos(offset);
  237.       m_slider.RedrawWindow();
  238.       //
  239.       strcpybuff(old_info,info);
  240.     }
  241.   }
  242.   //
  243.   CDialog::OnTimer(nIDEvent);
  244. }
  245.  
  246. void CInfoUrl::OnClose() 
  247. {
  248.   StopTimer();
  249.     CDialog::OnClose();
  250. }
  251.  
  252. void CInfoUrl::OnFreeze() 
  253. {
  254.   if (this->IsDlgButtonChecked(IDC_Freeze)) {
  255.     StopTimer();
  256.   } else {
  257.     StartTimer();
  258.   }
  259. }
  260.  
  261. int CInfoUrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  262. {
  263.     if (CDialog::OnCreate(lpCreateStruct) == -1)
  264.         return -1;
  265.     
  266.   timer=0;    
  267.  
  268.     return 0;
  269. }
  270.  
  271. void CInfoUrl::OnSelchangebacklist() 
  272. {
  273.   CString st;
  274.   int index=m_ctl_backlist.GetCurSel();
  275.   if (index!=CB_ERR) {
  276.     m_ctl_backlist.GetLBText(index,st);
  277.     int a=st.Find(':');
  278.     if (a>=0) {
  279.       char s[256]; s[0]='\0';
  280.       strncatbuff(s,st,a);
  281.       sscanf(s,"%d",&id);
  282.       this->OnTimer(0);
  283.     }
  284.   }
  285. }
  286.